<tagLib name="cx,html" />
<script type="text/javascript" src="__PUBLIC__/Js/JqueryAdapter.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/ThinkAjax.js"></script>
<script language="javascript">
ROOT = '__ROOT__';
ThinkAjax.image = ['__PUBLIC__/Images/ajaxloading.gif','__PUBLIC__/Images/ok.gif','__PUBLIC__/Images/error.gif'];
autoSaveTime = {$options.auto_save_time|Input::forShow}*60*1000;
//页面加载完成后启动定时器,每{$options.auto_save_time}分钟保存一下日志草稿
$(function(){
	window.setTimeout(saveDraft,autoSaveTime);
});

function saveDraft()
{
	var title = $('#post_title').attr('value');
	saveEditor(); //把FCK的内容保存到textarea
	var content = $('#editor').attr('value');
	if(title != '' && content != '') //两者有任意一个为空都不行
	{
		//如果是发布状态,先改成草稿,生成整个表单的序列化字符串后再改回来
		var postStatus = $('#post_status').attr('value');
		$('#post_status').attr('value','draft');
		$('#ajax').attr('value','1');
		ThinkAjax.sendForm('postForm','{:url("save","Blog")}',autoSaveResponse);		
		$('#post_status').attr('value',postStatus);
	}

	window.setTimeout(saveDraft,autoSaveTime); //触发下一次的自动保存
}

function autoSaveResponse(data,status)
{
	$('#ajax').attr('value','0');
	if(status == 1)
		$('#postid').attr('value',data);
}

function hideUploadWindow()
{
	tb_remove();
}

function PreView(filename,event)
{
	if (filename.match(/\.jpg|\.gif|\.png|\.bmp$/i)) {
		$("#preview").attr("src",""); //防止在本图像没下载完成时仍然显示上一张图片
		var bottom = 100;
		if(!document.all)
			bottom = $("#content").css("height").replace("px","")-event.pageY+130;
		else
			bottom = $("#content").attr("offsetHeight")-window.event.y-$("#header").attr("offsetHeight")+110;
		$("#preview").css({"display":"block","bottom":bottom+"px"});
		$("#preview").attr("src",filename);
	} else {
		return;
	}
}

function ClearPreview()
{
	$("#preview").css("display","none");
	$("#preview").attr("src","");
}

function addAttachment(id,html,remark,filename,image)
{
	$("#attach-content").append("<div id=\"attach_"+id+"\" class=\"attachment\"><a href=\"javascript:void(0);\" onclick=\"InsertHTML('"+html+"');\" onmouseover=\"PreView('"+filename+"',event);\" onmouseout=\"ClearPreview();\">[插入]</a> <a href=\"javascript:void(0);\" onclick=\"delAttach("+id+")\">[删除]</a> 附件: "+image+remark+" <span style=\"color: red\" id=\"attachSpan_"+id+"\"></span><input type=\"hidden\" name=\"attachId[]\" value=\""+id+"\" /><input type=\"hidden\" name=\"insertFile[]\" value=\""+filename+"\" /></div>");
}

function delAttach(id)
{
	if(confirm("删除附件会连同对应的文件一起删除，确认删除吗？"))
	{
		$('#attachSpan_'+id).html("<img src='__PUBLIC__/Images/loading.gif' />");
		//使用ajax先去把附件表里面的数据删除,再来把页面上的div删除
		$.ajax({
		   type: "POST",
		   url: "{:url('delAttach','Attach')}",
		   data: 'ajax=1&id='+id,
		   dataType: "json",
		   success: function(response){
				if(response.status == 1)
				{
					$("div").remove("#attach_"+id);
				}
				else
					$('#attachSpan_'+id).html(response.info);
		   }
		});
	}
}
</script>
<script type="text/javascript" src="__PUBLIC__/Js/thickbox/thickbox-compressed.js"></script>
<link rel="stylesheet" href="__PUBLIC__/Js/thickbox/thickbox.css" type="text/css" media="screen" />
<img id="preview" style="display: none; position: absolute; bottom: 100px; left: 100px; max-height: 400px;" />
<div id="box">
<h3>{$postAction}</h3>
<form method="post" id="postForm" action="{:url('save','Blog')}">
<h4>标题</h4>
<input type="text" class="txt" size="60" name="post_title" id="post_title" value="{$post.post_title|Input::forTag}"><input type="hidden" id="postid" name="ID" value="{$post.ID|Input::forTag}">&nbsp;&nbsp;&nbsp;短标题&nbsp;<input type="text" name="post_name" class="txt" value="{$post.post_name|Input::forTag}">
<h4>内容</h4>
<html:editor type="fckeditor" id="editor" width="700px" height="400px" name="post_content"  content="{$post.post_content|Input::forTarea}"/>
<h4>附件</h4>
<div id="attach-content">
<!--附件上传以及列表-->
<script language="javascript">
<volist name="attachList" id="attach">
	{$attach}
</volist>
</script>
<!--附件内容插入编辑区域 FCKeditorAPI.GetInstance('editor').InsertHtml('<img src=\'/moo.jpg\'>')-->
</div>
<p><a class="thickbox" href="{$Think.server.PHP_SELF}?KeepThis=true&m=Attach&a=upload&TB_iframe=true&height=200&width=480" title="上传附件">添加附件</a></p>
<!--因为后台使用普通模式的URL,所以不需要使用url函数来组装-->
<h4>分类</h4>
日志分类&nbsp;<html:select name="post_category" id="post_category" options="categoryList" selected="selectCid" /><input type="hidden" name="pre_category" value="{$selectCid}">&nbsp;&nbsp;日志类别&nbsp;<html:select name="post_type" id="post_type" options="typeList" selected="selectType" />
<h4>标签(Tag)</h4>
<input type="text" name="tags" size="40" class="txt" value="{$tags|Input::forTag}" /> 半角逗号(,)分隔
<h4>状态</h4>
是否发布&nbsp;<html:select name="post_status" id="post_status" options="post_statusList" selected="selectPost_status" />&nbsp;&nbsp;
是否置顶&nbsp;<html:select name="top" id="top" options="topList" selected="selectTop" />&nbsp;&nbsp;
允许评论&nbsp;<html:select name="comment_status" id="comment_status" options="statusList" selected="selectComment_status" />&nbsp;&nbsp;
引用通告&nbsp;<html:select name="ping_status" id="ping_status" options="statusList" selected="selectPing_status" />
<present name="post['post_date']">
<h4>时间</h4>
<input type="checkbox" class="checkbox" id="mod_time" onclick="$('#post_date').attr('disabled',function(){ if($('#post_date').attr('disabled')) return ''; else return 'disabled'; })">自定义时间&nbsp;<input type="text" id="post_date" name="post_date" size="15" value="{$post.post_date|Input::forTag}" class="txt" disabled="disabled">
</present>
<if condition="!strstr(get_cfg_var('disable_functions'),'fsockopen')">
<h4>为下面的地址发送引用通告(多个地址使用;分隔)</h4>
<input name="trackbackUrl" class="txt" size="60" />
</if>
<p><input type="hidden" name="ajax" id="ajax" value="0" /><input name="submit" type="submit" class="btn" value="提交" onclick="$('#ajax').attr('value','0');" />&nbsp;<input type="button" class="btn" value="返回" onclick="history.go(-1)" /></p>
</form>
</div>